﻿#region MIT
/*
Green.Logging
Part of Engine Of Evermore (http://code.google.com/p/engineofevermore/)
Copyright (c) 2008 Michael Woerister

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Green.Logging
{
    public enum LogEntryType
    {
        Info,
        Warning,
        Error
    }

    public struct LogEntry
    {
        public LogEntry( String message, LogEntryType type )
        {
            Message = message;
            Type = type;
        }

        public readonly String Message;
        public readonly LogEntryType Type;
    }

    public delegate void LogEntryAddedDelegate( LogEntry entry );

    public static class Log
    {
        #region Variables
        static List<LogEntry> _entries = new List<LogEntry>();
        #endregion

        #region Events
        public static event LogEntryAddedDelegate EntryAdded;
        #endregion

        #region Properties
        public static IEnumerable<LogEntry> Entries
        {
            get 
            {
                return _entries;
            }
        }
        #endregion

        #region Methods
        public static void Info( String message )
        {
            LogEntry entry = new LogEntry( message, LogEntryType.Info );
            _entries.Add( entry );
            _raiseEntryAddedEvent( entry );
        }

        public static void Warning( String message )
        {
            LogEntry entry = new LogEntry( message, LogEntryType.Warning );
            _entries.Add( entry );
            _raiseEntryAddedEvent( entry );
        }

        public static void Error( String message )
        {
            LogEntry entry = new LogEntry( message, LogEntryType.Error );
            _entries.Add( entry );
            _raiseEntryAddedEvent( entry );
        }

        static void _raiseEntryAddedEvent( LogEntry entry )
        {
            if ( EntryAdded != null )
            {
                EntryAdded( entry );
            }
        }
        #endregion
    }
}
